package com.qfedu.service.impl;

import com.qfedu.mapper.DeveloperMapper;
import com.qfedu.mapper.DeveloperMapper;
import com.qfedu.model.Developer;
import com.qfedu.model.Developer;
import com.qfedu.page.PageResult;
import com.qfedu.page.QueryPageBean;
import com.qfedu.service.DeveloperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author LiJH
 * @date 2023-02-10
 */
@Service
public class DeveloperServiceImpl implements DeveloperService {
    @Autowired
    private DeveloperMapper developerMapper;
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {

        PageResult pageResult = new PageResult();
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        long count = developerMapper.count();
        pageResult.setTotal(count);
        List<Developer> page = developerMapper.findPage((currentPage - 1) * pageSize, pageSize);
        pageResult.setRows(page);
        return pageResult;
    }

    @Override
    public int addDeveloper(Developer developer) {
        developer.setUpdatetime(new Date());
        return developerMapper.addDeveloper(developer);
    }

    @Override
    public Developer findDeveByDid(String did) {
        return   developerMapper.findDeveByDid(did);
    }

    @Override
    public int editDeveloper(Developer developer) {
        developer.setUpdatetime(new Date());
        int i = developerMapper.editDeveloper(developer);
        return i;
    }

    @Override
    public int deleteByDid(String did) {
        return developerMapper.deleteByDid(did);
    }
}